<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *公告管理
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
if($_RQ['op']=='list'){
	$params=array('uniacid'=>$_SESSION['uniacid']);
	if($_RQ['storeid']){
		$params['storeid']=$_RQ['storeid'];
		$return['params']['storeid']=$_RQ['storeid'];
	}
	$y=$_RQ['y']?:date('Y');
	$m=$_RQ['m']?:date('m');
	if(!empty($_RQ['y'])){
		$return['params']['y']=$_RQ['y'];
	}
	if(!empty($_RQ['m'])){
		$return['params']['m']=$_RQ['m'];
	}
	$daynum=date("t",strtotime($y.'-'.$m));
	$list=array();
	for($i=1;$i<=$daynum;$i++){
		$starttime=strtotime($y.'-'.$m.'-'.$i);
		$endtime=$starttime+24*3600;
		$params['jiao_time between']=array($starttime,$endtime);
		$heparams=$params;
		if($params['storeid']){
			unset($heparams['storeid']);
			$heparams['hestoreid']=$params['storeid'];
		}
		$params['type']=0;
		$fee1=pdo_getsum('jy_yxw_feelog',$params,'fee');
		$item['fee1jian']=pdo_getsum('jy_yxw_feelog',$params,'hefee');
		if($item['fee1jian']){
			$fee1-=$item['fee1jian'];
		}
		$heparams['type']=0;
		$item['fee1he']=pdo_getsum('jy_yxw_feelog',$heparams,'hefee');
		if($item['fee1he']){
			$fee1+=$item['fee1he'];
		}
		$params['type']=1;
		$fee2=pdo_getsum('jy_yxw_feelog',$params,'fee');
		$item['fee2jian']=pdo_getsum('jy_yxw_feelog',$params,'hefee');
		if($item['fee1jian']){
			$fee2-=$item['fee2jian'];
		}
		$heparams['type']=1;
		$item['fee2he']=pdo_getsum('jy_yxw_feelog',$heparams,'hefee');
		if($item['fee2he']){
			$fee2+=$item['fee2he'];
		}
		$params['type']=2;
		$fee3=pdo_getsum('jy_yxw_feelog',$params,'fee');
		$item['fee3jian']=pdo_getsum('jy_yxw_feelog',$params,'hefee');
		if($item['fee3jian']){
			$fee3-=$item['fee3jian'];
		}
		$heparams['type']=2;
		$item['fee3he']=pdo_getsum('jy_yxw_feelog',$heparams,'hefee');
		if($item['fee3he']){
			$fee3+=$item['fee3he'];
		}
		$params['type']=3;
		$fee4=pdo_getsum('jy_yxw_feelog',$params,'fee');
		$params['type']=4;
		$fee5=pdo_getsum('jy_yxw_feelog',$params,'fee');
		$allfee=$fee1+$fee2+$fee3-$fee4-$fee5;
		$list[]=array(
			'title'=>$y.'-'.$m.'-'.$i,
			'allfee'=>$allfee,
			'fee1'=>$fee1,
			'fee2'=>$fee2,
			'fee3'=>$fee3,
			'fee4'=>$fee4,
			'fee5'=>$fee5,
		);
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'export'=>'export',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','edit'=>false,'del_one'=>false,'delall'=>false,'list'=>array(
			array('name'=>'title','title'=>'日期','type'=>'string'),
			array('name'=>'allfee','title'=>'实收合计','type'=>'string'),
			array('name'=>'fee2','title'=>'定金','type'=>'string'),
			array('name'=>'fee1','title'=>'单费','type'=>'string'),
			array('name'=>'fee3','title'=>'分期收费','type'=>'string'),
			array('name'=>'fee5','title'=>'退定金','type'=>'string'),
			array('name'=>'fee4','title'=>'退单费','type'=>'string'),
		)),
		'search'=>array(
			array('name'=>'storeid','width'=>15,'title'=>'所属门店','type'=>'select','options'=>'stores'),
			array('name'=>'y','width'=>15,'title'=>'年份','type'=>'radio','options'=>'ys'),
			array('name'=>'m','width'=>15,'title'=>'月份','type'=>'radio','options'=>'months'),
		)
	);
	$return['stores']=$this->getall('store',array('uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');
	$return['htmls']=$htmls;
	$nowy=date('Y');
	$y1=$nowy-2;
	$y2=$nowy-1;
	$return['ys']=array(
		$y1=>$y1.'年',
		$y2=>$y2.'年',
		$nowy=>$nowy.'年',
	);
	$return['months']=array(
		'1'=>'1月',
		'2'=>'2月',
		'3'=>'3月',
		'4'=>'4月',
		'5'=>'5月',
		'6'=>'6月',
		'7'=>'7月',
		'8'=>'8月',
		'9'=>'9月',
		'10'=>'10月',
		'11'=>'11月',
		'12'=>'12月',
	);
	exi($return);
}
if($_RQ['op']=='export'){
	$params=array('uniacid'=>$_SESSION['uniacid']);
	if($_RQ['storeid']){
		$params['storeid']=$_RQ['storeid'];
		$return['params']['storeid']=$_RQ['storeid'];
	}
	$y=$_RQ['y']?:date('Y');
	$m=$_RQ['m']?:date('m');
	if(!empty($_RQ['y'])){
		$return['params']['y']=$_RQ['y'];
	}
	if(!empty($_RQ['m'])){
		$return['params']['m']=$_RQ['m'];
	}
	$daynum=date("t",strtotime($y.'-'.$m));
	$list=array();
	for($i=1;$i<=$daynum;$i++){
		$starttime=strtotime($y.'-'.$m.'-'.$i);
		$endtime=$starttime+24*3600;
		$params['jiao_time between']=array($starttime,$endtime);
		$heparams=$params;
		if($params['storeid']){
			unset($heparams['storeid']);
			$heparams['hestoreid']=$params['storeid'];
		}
		$params['type']=0;
		$fee1=pdo_getsum('jy_yxw_feelog',$params,'fee');
		$item['fee1jian']=pdo_getsum('jy_yxw_feelog',$params,'hefee');
		if($item['fee1jian']){
			$fee1-=$item['fee1jian'];
		}
		$heparams['type']=0;
		$item['fee1he']=pdo_getsum('jy_yxw_feelog',$heparams,'hefee');
		if($item['fee1he']){
			$fee1+=$item['fee1he'];
		}
		$params['type']=1;
		$fee2=pdo_getsum('jy_yxw_feelog',$params,'fee');
		$item['fee2jian']=pdo_getsum('jy_yxw_feelog',$params,'hefee');
		if($item['fee1jian']){
			$fee2-=$item['fee2jian'];
		}
		$heparams['type']=1;
		$item['fee2he']=pdo_getsum('jy_yxw_feelog',$heparams,'hefee');
		if($item['fee2he']){
			$fee2+=$item['fee2he'];
		}
		$params['type']=2;
		$fee3=pdo_getsum('jy_yxw_feelog',$params,'fee');
		$item['fee3jian']=pdo_getsum('jy_yxw_feelog',$params,'hefee');
		if($item['fee3jian']){
			$fee3-=$item['fee3jian'];
		}
		$heparams['type']=2;
		$item['fee3he']=pdo_getsum('jy_yxw_feelog',$heparams,'hefee');
		if($item['fee3he']){
			$fee3+=$item['fee3he'];
		}
		$params['type']=3;
		$fee4=pdo_getsum('jy_yxw_feelog',$params,'fee');
		$params['type']=4;
		$fee5=pdo_getsum('jy_yxw_feelog',$params,'fee');
		$allfee=$fee1+$fee2+$fee3-$fee4-$fee5;
		$list[]=array(
			'title'=>$y.'-'.$m.'-'.$i,
			'allfee'=>$allfee,
			'fee1'=>$fee1,
			'fee2'=>$fee2,
			'fee3'=>$fee3,
			'fee4'=>$fee4,
			'fee5'=>$fee5,
		);
	}
	$header=array(
		'title'=>'日期',
		'allfee'=>'实收合计',
		'fee2'=>'定金',
		'fee1'=>'单费',
		'fee5'=>'退定金',
		'fee4'=>'退单费',
		'fee3'=>'分期收费',
	);
	cfc('tools')->export2excel($header,$list,'日收入');
}